package com.jisuan.contract.controller;

import com.jisuan.contract.common.utils.PageResult;
import com.jisuan.contract.common.utils.Result;
import com.jisuan.contract.entity.BorrowingUserEntity;
import com.jisuan.contract.service.BorrowingUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 借阅人表
 *
 * @author 王大军
 * @email wangdajunzy@163.com
 * @date 2022-01-07 12:05:38
 */
@RestController
@RequestMapping("contract/borrowingUser")
public class BorrowingUserController
{
    @Autowired
    private BorrowingUserService borrowingUserService;

    /**
     * 列表
     */
    @GetMapping
    public Result<PageResult> list(@RequestParam Map<String, Object> params,
                                   BorrowingUserEntity borrowingUser)
    {
        PageResult pageResult = borrowingUserService.queryPage(params, borrowingUser);

        return Result.success(pageResult);
    }


    /**
     * 信息
     */
    @GetMapping("/{id}")
    public Result<BorrowingUserEntity> info(@PathVariable("id") Long id)
    {
        BorrowingUserEntity borrowingUser = borrowingUserService.getById(id);
        return Result.success(borrowingUser);
    }

    /**
     * 保存
     */
    @PostMapping
    public Result<?> save(@RequestBody BorrowingUserEntity borrowingUser)
    {
        borrowingUserService.save(borrowingUser);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping
    public Result<?> update(@RequestBody BorrowingUserEntity borrowingUser)
    {
        borrowingUserService.updateById(borrowingUser);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping
    public Result<?> delete(@RequestBody Long[] ids)
    {
        borrowingUserService.removeByIds(Arrays.asList(ids));
        return Result.success();
    }
}
